<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Banner extends MY_Luckydog
{
	public function __construct()
	{
		parent::__construct();
      /*  $func = $this->router->fetch_method();
        if($func != "upload_cover"){
            $login_status = $this->check_login_status();
            if ($login_status === FALSE){
                header("Location:login");
            }
        }*/
        $this->load->model('luckydog/Banner_model', 'banner');
	}

/**
 * 新闻列表
 * @return [type] [description]
 */
    public function index(){
        $login_status = $this->check_login_status();
        $_SESSION['v_menu'] = 'banner';
        $bannerList = $this->banner->getBannerList();
        $data = array(
            'bannerList'=>$bannerList,
            );
        $this->load->view("/luckydog/banner/index", $data);
    }

    public function textures()
    {
        $login_status = $this->check_login_status();
        $id = $this->input->get("id",true)?$this->input->get("id",true):"";
        if ($login_status === FALSE){
            header("Location:login");
        }
        $_SESSION['v_menu'] = 'ad';
        $data = array();
        if(!empty($id)){
            $AdInfo = $this->banner->getAdInfobyID($id);
            $data["AdInfo"] = $AdInfo;
        }
    	$this->load->view("/luckydog/banner/textures", $data);
    }

    //编辑广告
    public function editBanner(){
        $id = $this->input->post("id",true) ? $this->input->post("id",true) : 0;
        $banner_img = $this->input->post("banner_img",true) ? $this->input->post("banner_img",true) : "";
        $sort_order = $this->input->post("sort_order",true) ? $this->input->post("sort_order",true) : "0";
        $data = array(
            "banner_img"=>$banner_img,
            "sort_order"=>$sort_order
        );
        if(empty($id)){
            $data['add_time']=time();
        }
        $res = $this->banner->editAd($id,$data);
        echo $res;
    }


    public function upload_cover()
    {
        $this->load->library('Upload');
        $upload = new Upload();
        $file_name =$upload->execute($_FILES['Filedata']);
      
        if(is_string($file_name))
        {
            $res=json_encode(array('code'=>1,'type'=>0,'file_name'=>$file_name));

            echo $res;
        }
        else
        {
            echo json_encode(array('code'=>-1));
        }
    }

    //删除状态
    public function delBanner(){
        $id = $this->input->post("id",true) ? $this->input->post("id",true) : 0;
        $res =$this->banner->delAd($id);
        echo $res;
    }


}
/* End of file index.php */
/* Location: ./application/controllers/luckydog/index.php */